import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { IsEnum, IsNotEmpty, isNumber } from "class-validator";
import { PageDto } from "src/common/dto/dto";
import { OrderState } from "src/dictionaries/index.enum";
import { FindOperator } from "typeorm";
import { OrderType, PayType } from "../entities/order.entity";

export class GetOrderDto extends PageDto {
    /** 订单编号 */
    @ApiPropertyOptional({
        type: String,
        name: 'orderNo',
        description: '订单编号',
    })
    public readonly orderNo: string;

    /** 订单状态 */
    @ApiPropertyOptional({
        name: 'status',
        description: '订单状态',
        enum: OrderState,
    })
    public readonly status: OrderState;

    /** 用户ID */
    @ApiPropertyOptional({
        type: String,
        name: 'userId',
        description: '用户ID',
    })
    public readonly userId: number;

    /** 支付类型 */
    @ApiPropertyOptional({
        name: 'payType',
        description: '支付类型',
        enum: PayType,
    })
    public readonly payType: PayType;

    /** 订单类型 */
    @ApiPropertyOptional({
        name: 'type',
        description: '订单类型',
        enum: OrderType,
    })
    public readonly type: OrderType;
}

export class CreateOrderDto {
    /** 用户Id */
    @IsNotEmpty({ message: '用户Id不能为空' })
    @ApiProperty({
        type: Number,
        name: 'userId',
        description: '用户Id',
    })
    public readonly userId?: number;
    /** 支付类型 */
    @IsEnum(PayType)
    @IsNotEmpty({ message: '支付类型不能为空' })
    @ApiPropertyOptional({
        name: 'payType',
        description: '支付类型',
        enum: PayType,
    })
    public readonly payType: PayType;

    /** 订单类型 */
    @IsEnum(OrderType)
    @IsNotEmpty({ message: '订单类型不能为空' })
    @ApiPropertyOptional({
        name: 'type',
        description: '订单类型',
        enum: OrderType,
    })
    public readonly type: OrderType;

    /** 金额 */
    @IsNotEmpty({ message: '金额不能为空' })
    @ApiProperty({
        type: Number,
        name: 'amount',
        description: '金额',
    })
    public readonly amount?: number;
}
export class UpdateOrderDto {
    @IsNotEmpty({ message: 'id不能为空' })
    @ApiProperty({
        type: Number,
        name: 'id',
        description: 'id',
    })
    public readonly id: number;
    /** 用户Id */
    @IsNotEmpty({ message: '用户Id不能为空' })
    @ApiProperty({
        type: Number,
        name: 'userId',
        description: '用户Id',
    })
    public readonly userId?: number;

    /** 订单状态 */
    @IsEnum(OrderState)
    @IsNotEmpty({ message: '订单状态不能为空' })
    @ApiPropertyOptional({
        name: 'status',
        description: '订单状态',
        enum: OrderState,
    })
    public readonly status: OrderState;
    /** 支付类型 */
    @IsEnum(PayType)
    @IsNotEmpty({ message: '支付类型不能为空' })
    @ApiPropertyOptional({
        name: 'payType',
        description: '支付类型',
        enum: PayType,
    })
    public readonly payType: PayType;

    /** 订单类型 */
    @IsEnum(OrderType)
    @IsNotEmpty({ message: '订单类型不能为空' })
    @ApiPropertyOptional({
        name: 'type',
        description: '订单类型',
        enum: OrderType,
    })
    public readonly type: OrderType;
}